﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="advertisement.aspx.cs" Inherits="admin_advertisement" %>

<%@ Import Namespace="Infrastructure.Utility" %>
<asp:Content ContentPlaceHolderID="titleContent" runat="Server">
    广告设置
</asp:Content>
<asp:Content ContentPlaceHolderID="headContent" runat="Server">
    <link href="/content/uploadify/uploadify.css" rel="stylesheet" />
</asp:Content>
<asp:Content ContentPlaceHolderID="mainContent" runat="Server">
    <h4>广告设置</h4>
    <form runat="server" class="form-horizontal">
        <div>
            <div class="pull-left" style="margin-bottom: 2px;">
                <div style="width: 450px;" class="input-group">
                    <asp:TextBox class="form-control" placeholder="输入关键字检索." runat="server" ID="txtName" onkeydown="if(event.keyCode == 13) $('.searchbutton').click();" />
                    <span class="input-group-addon" style="cursor: pointer;" id="sizing-addon1" onclick="$('.searchbutton').click();"><i class="cus-icon-search">&nbsp;</i></span>
                </div>
                <span class="hidden">
                    <asp:Button runat="server" name="btnPost" CssClass="searchbutton" OnClick="btnPost_Click" UseSubmitBehavior="false" />
                </span>
            </div>
            <div class="pull-right" style="margin-bottom: 2px;">
                <a class="btn btn-success" href="#editing-row" onclick="addNewRow(this);"><i class="cus-icon-add"></i>增加</a>
                <a class="btn btn-danger" onclick="if(checkSelected()) $('.deletebutton').click();"><i class="cus-icon-delete"></i>删除</a>
                <span class="hidden">
                    <asp:Button runat="server" name="btnDel" UseSubmitBehavior="false" CssClass="hidden deletebutton" OnClick="btnDel_Click" />
                </span>
            </div>
        </div>
        <input type="hidden" id="txtGoTo" name="txtGoTo" value="0" />
        <table class="table gridview">
            <tr>
                <th>
                    <input type="checkbox" onchange="$(this).parentsUntil('table').find('.selector').attr('checked',this.checked);" />
                    选择
                </th>
                <th>类型</th>
                <th>标题</th>
                <th>说明</th>
                <th>点击量</th>
                <th>状态</th>
                <th>创建时间</th>
                <th>创建者</th>
                <th>操作</th>
            </tr>
            <tr class="hidden edit-row-tpl">
                <td>

                    <a class="btn btn-danger" onclick="$('.searchbutton').click();" href="javascript:void(0);">取消</a>
                    <input type="hidden" name="adid_tpleditor" /></td>
                <td>
                    <select placeholder="类型" name="adtype_tpleditor" class="form-control">
                        <option value="0">首页轮播广告</option>
                    </select></td>
                <td>
                    <input name="adtitle_tpleditor" placeholder="标题" class="form-control" /></td>
                <td>
                    <input name="addescription_tpleditor" placeholder="描述" class="form-control" /></td>
                <td colspan="2">
                    <asp:FileUpload runat="server" ID="adimage_tpleditor" CssClass="form-control" placeholder="广告图片" ToolTip="请选择广告图片" /></td>
                <td colspan="2">
                    <input name="adurl_tpleditor" placeholder="链接地址" class="form-control" /></td>
                <td>
                    <asp:Button CssClass="btn btn-success" Text="保存" ID="btnSaveEdit" runat="server" OnClick="btnSaveEdit_Click" /></td>
            </tr>
            <asp:Repeater ID="lstAdvertisement" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <input type="checkbox" class="selector" name="selector" value="<%# Eval("adid") %>" />
                            <input type="hidden" />
                        </td>
                        <td>
                            <input type="hidden" class="adtype-value" value="<%#Eval("adtype") %>" /><%#Eval("adtypename") %>
                        </td>
                        <td>
                            <input type="hidden" class="adurl-value" value="<%#Eval("adurl") %>" />
                            <a href="<%# Eval("adurl") %>" target="_blank" title="<%#Eval("adurl") %>"><%#Eval("adtitle") %></a>
                        </td>
                        <td><%#Eval("addescription") %></td>
                        <td><%#Eval("adclicks") %></td>
                        <td>
                            <input type="checkbox" <%#(int)Eval("adstatus") == 1 ? "checked":string.Empty %> />
                        </td>
                        <td><%#Eval("creator") %></td>
                        <td><%#Eval("systime") %></td>
                        <td><a href="javascript:void(0);" onclick="editAdRow(this);">编辑</a></td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
        <div>
            <div class="btn-group pull-left" role="group">
                <button type="button" class="btn btn-default" onclick="$('#txtGoTo').val('1');$('.gotoindex').click();">1</button>
                <button type="button" class="btn btn-default" onclick="$('#txtGoTo').val('<%=Index-1 %>');$('.gotoindex').click();"><<</button>
                <button type="button" class="btn btn-default" onclick="$('#txtGoTo').val('<%=Index+1 %>');$('.gotoindex').click();">>></button>
                <button type="button" class="btn btn-default" onclick="$('#txtGoTo').val('<%=TotalSize %>');$('.gotoindex').click();"><%=TotalSize %></button>
                <input type="text" class="form-control" style="width: 20px; margin-left: 2px;" placeholder="Go" onkeydown="if(event.keyCode==13) { $('#txtGoTo').val(this.value);$('.gotoindex').click();}" />
                <asp:Button runat="server" CssClass="hidden gotoindex" UseSubmitBehavior="false" OnClick="btnNavigate_Click" />
            </div>
            <div class="pull-right">
                <%=Index %>/<%=TotalSize %>页
            </div>
        </div>


        <%--<div class="tooltip bottom" role="tooltip">
            <div class="tooltip-arrow"></div>
            <div class="tooltip-inner">
                <div>
                    <img src="" />
                </div>
                <p></p>
            </div>
        </div>--%>
    </form>
</asp:Content>
<asp:Content ContentPlaceHolderID="scriptContent" runat="Server">
    <script type="text/javascript">
        //验证点击删除时，是否勾选了项目。
        function checkSelected() {
            var hasSel = false;
            $(".selector").each(function (index, e) {
                if (this.checked) return hasSel = true;
            });

            if (!hasSel) {
                alert("请勾选需要删除的项目！");
                return false;
            }
            return true;
        }

        function addNewRow(sender) {
            $(sender).hide();
            var row = $("<tr id='editing-row' class='editing-row'>").html($(".edit-row-tpl").html().replace(/_tpleditor/g, ""));
            $(".gridview").append(row);//$(".edit-row-tpl").clone(true, true).removeClass("hidden").removeClass("edit-row-tpl").addClass("editing-row").attr("id", "editing-row").html().replace(/_tpleditor/g, "")
            $(".editing-row").find("select[name='adtypename']").focus();
        }
        function editAdRow(sender) {
            if ($(".editing-row").length > 0) return alert("您正在编辑其他广告，请保存后再试！");
            var cell = $(sender).parentsUntil("tr")[0];
            var row = $(cell.parentNode).hide();
            var editrow = $("<tr id='editing-row' class='editing-row'>").html($(".edit-row-tpl").html().replace(/_tpleditor/g, ""));

            //var tplrow = $(".edit-row-tpl").clone(true, true).removeClass("hidden").removeClass("edit-row-tpl").addClass("editing-row");
            //$(tplrow.html().replace(/_tpleditor/g, "")).insertBefore(row);
            editrow.insertAfter(row);
            editrow.find("select[name='adtype']").val(row.find(".adtype-value").val()).focus();
            editrow.find("input[name='adtitle']").val(row[0].children[2].innerText);
            editrow.find("input[name='addescription']").val(row[0].children[3].innerText);
            editrow.find("input[name='adurl']").val(row.find(".adurl-value").val());
            editrow.find("input[name='adid']").val(row.find(".selector").val());

        }
    </script>
</asp:Content>

